package org.footballmanager.pandafootball.common.job;

import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootCupbf;
import org.footballmanager.pandafootball.system.service.FootCupbfService;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;
import java.util.Map;

/**
 * 定时任务类
 * 实现了定时任务的基类
 * 并需要实现其父类里的方法
 *
 * @author chenjian
 * @since 2017年10月18日下午5:17:22
 */
@Slf4j
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class CupBfJob extends QuartzJobBean {
    @Autowired
    private FootCupbfService footCupbfService;

    /**
     * 解锁1小时后数据库内的数据
     *
     * @param context 内容
     * @throws JobExecutionException 异常
     */
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("OtherJob执行时间: " + new Date());
        JobDataMap map = jobExecutionContext.getMergedJobDataMap();
        if (map == null || map.isEmpty()) {
            return;
        }
        @SuppressWarnings("unchecked")
        Map<String, Object> paramMap = (Map<String, Object>) map.get("paramMap");
        Long id = (Long) paramMap.get(Constants.ID);
        if (null != footCupbfService && id != null) {
            FootCupbf bf = new FootCupbf();
            bf.setId(id);
            footCupbfService.makesure(bf, null);
        }
    }

}